<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="学号" width="180">
        <template slot-scope="scope">
          <!-- <i class="el-icon-time"></i> -->
          <span style="margin-left: 10px">{{ scope.row.student_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>所在班级id: {{ scope.row.grade_id}}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.student_name }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="密码" width="180">
        <template slot-scope="scope">
          <!-- <i class="el-icon-time"></i> -->
          <span style="margin-left: 10px">{{ scope.row.student_pwd }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleModify(scope.$index, scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="修改" :visible.sync="modifyDialog">
      <el-form :model="form" class="modifyForm">
        <el-form-item label="学号" :label-width="modifyDialogWidth">
          <el-input v-model="form.student_id" autocomplete="off">123</el-input>
        </el-form-item>
        <el-form-item label="姓名" :label-width="modifyDialogWidth">
          <el-input v-model="form.student_name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="modifyDialogWidth">
          <el-input v-model="form.student_pwd" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="modifyDialog = false">取 消</el-button>
        <el-button type="primary" @click="handlemodifyDialog"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getStudent,delStudent} from '../../../api/student'
export default {
  data() {
    return {
      modifyDialog: false,
      modifyDialogWidth: "65px",
      modifyDialogIndex:"",
      form: {
        name: "",
        address: "",
        class: "",
      },
      tableData: [

      ],
    };
  },
  methods: {

    handleDelete(index, row) {
      delStudent({
          params:{
        id:row.student_id
      }
      }).then(res=>{
        console.log(res);
      })
      console.log(index, row);
    },
    handleModify(index, row) {
      console.log(index);
      this.modifyDialog = !this.modifyDialog;
      this.modifyDialogIndex = index
      this.form.student_id = row.student_id;
      this.form.student_name = row.student_name;
      this.form.student_pwd = row.student_pwd;
      this.form.grade_id = row.grade_id;
      
    },
    handlemodifyDialog(){
      this.modifyDialog = !this.modifyDialog;
      this.tableData[this.modifyDialogIndex].student_id=  this.form.student_id
      this.tableData[this.modifyDialogIndex].student_name=  this.form.student_name
      this.tableData[this.modifyDialogIndex].student_pwd =  this.form.student_pwd
      this.tableData[this.modifyDialogIndex].grade_id =  this.form.grade_id
    },
  
  },
    mounted(){
      getStudent().then(res =>{
        this.tableData=res.data.data
        console.log(this.tableData);
      })
    }
};
</script>
<style lang="scss" scoped>

</style>